<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane" action="" id="formInfo">
            <!--<fieldset class="table-search-fieldset">-->
            <!--<legend>搜索信息</legend>-->
            <div style="margin: 10px 10px 10px 10px">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">搜索信息</label>
                        <div class="layui-input-inline" style="width: 250px">
                            <input type="text" name="searchInfo" placeholder="请输入购买人/出售人的名称/手机号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline" style="display: none">
                        <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索
                        </button>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">交易状态</label>
                        <div class="layui-input-inline" style="width: 100px;">
                            <select name="trad_status" lay-filter="selectedInfo">
                                <option value=""></option>
                                <option value="1">待确认</option>
                                <option value="2">已确认</option>
                                <option value="3">超时交易</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">时间筛选</label>
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" name="searchTime_min" id="searchTime_min" placeholder="起始日期" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid">-</div>
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" name="searchTime_max" id="searchTime_max" placeholder="结束日期" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>

            </div>
            <!--</fieldset>-->
        </form>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="detailInfo">查看详情</a>
            {{#  if(d.trad_status != 2){ }}
            <a class="layui-btn layui-btn-xs layui-btn-danger " lay-event="violations">违规判定</a>
            {{#  } }}
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>
    </div>
</div>
{include file="public/footer" /}
<!--类型-->
<script type="text/html" id="statusTpl">
    {{#  if(d.trad_status === 1){ }}
    <span>待确认</span>
    {{# }else if(d.trad_status === 2){ }}
    <span>已确认</span>
    {{#  } else { }}
    <span>超时交易</span>
    {{#  } }}
</script>

<script>
    var lanunchdetail="{$lanunchdetail}";
    var member_phone="{$member_phone}";
    var source="{$source}";
    var buy_code="{$buy_code}";
    var business_id="{$business_id}";
    layui.use(['form', 'table', 'laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate;
        /*时间-最小*/
        laydate.render({
            elem: '#searchTime_min',
            done: function (value, date) {
                $('#searchTime_min').val(value);
                submitInfo();
            }
        });
        /*时间-最大*/
        laydate.render({
            elem: '#searchTime_max',
            done: function (value, date) {
                $('#searchTime_max').val(value);
                submitInfo();
            }
        });
        /*交易记录*/
        table.render({
            elem: '#currentTableId',
            url: '/admin/PlatformData/tradAudit?action=ajax&lanunchdetail='+lanunchdetail+"&member_phone="+member_phone+"&source="+source+"&buy_code="+buy_code+"&business_id="+business_id,
            method: 'post',
            where: {read_status: "{$read_status}"},
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data, //解析数据列表
                };
            },
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {
                    field: 'buy_name', title: '购买人名称', sort: true, align: 'center', event: 'checkBuyInfo', style: 'cursor: pointer;',
                    templet: function (d) {
                        return '<a href="#" style="color: #1e9fff;text-decoration: underline;">' + d.buy_name + '</a>';
                    }
                },
                {field: 'buy_phone', title: '购买人手机号', sort: true, align: 'center'},
                {field: 'industry_title', title: '生意名称', sort: true, align: 'center'},
                {field: 'price', title: '交易金额', sort: true, align: 'center'},
                {
                    field: 'screenshot', title: '交易截图', sort: true, align: 'center',
                    templet: function (d) {
                        return '<button class="layui-btn layui-btn-sm" onclick="showImg(\'' + d.screenshot + '\')">查看</button>';
                    }
                },
                {
                    field: 'sell_name', title: '出售人名称', sort: true, align: 'center', event: 'checkSellInfo', style: 'cursor: pointer;',
                    templet: function (d) {
                        return '<a href="#" style="color: #1e9fff;text-decoration: underline;">' + d.sell_name + '</a>';
                    }
                },
                {field: 'sell_phone', title: '出售人手机号', sort: true, align: 'center'},
                {field: 'trad_time', title: '交易时间', sort: true, align: 'center'},
                {field: 'trad_status', title: '交易状态', sort: true, templet: '#statusTpl', align: 'center'},
                {title: '操作', toolbar: '#currentTableBar', width: '15%', align: 'center'}
            ]],
            limits: [10, 15, 20, 25, 30, 50, 100],
            limit: 10,
            page: true,
            skin: 'line,row',
            done: function (res, curr, count) {

            }
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            submitInfo();
            return false;
        });

        // 监听select筛选
        form.on('select(selectedInfo)', function (data) {
            submitInfo();
            return false;
        });

        function submitInfo() {
            var d = {};
            var t = $('#formInfo [name]').serializeArray();
            $.each(t, function () {
                d[this.name] = this.value;
            });
            var result = JSON.stringify(d);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');
            return false;
        }

        /*查看详情*/
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detailInfo') {
                var index = layer.open({
                    title: '查看详情',
                    type: 2,
                    shade: 0.5,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/PlatformData/tradAudit?action=detail&id=' + data.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'violations') {
                layer.confirm('确定判定购买方违规吗？<br/>判定违规后，将终止双方交易，并恢复相关状态，购买方将被冻结账号！', function (index) {
                    $.ajax({
                        url: '/admin/PlatformData/tradAudit?action=violations',
                        type: 'post',
                        dataType: 'json',
                        data: {id: data.id},
                        success: function (res) {
                            if (res.status == true) {
                                // 关闭弹出层
                                layer.msg("违规判定成功");
                                layer.close(index);
                            } else {
                                layer.close(index);
                                layer.msg(res.msg);
                            }
                        },
                        error: function () {
                            layer.msg("报错了");
                        }
                    });
                });
            }
            else if (obj.event === 'delete') {
                layer.confirm('确定删除吗？', function (index) {
                    $.ajax({
                        url: '/admin/PlatformData/tradAudit?action=delete',
                        type: 'post',
                        dataType: 'json',
                        data: {id: data.id},
                        success: function (res) {
                            if (res.status == true) {
                                // 关闭弹出层
                                layer.msg("删除成功");
                                obj.del(this);
                                layer.close(index);
                            } else {
                                layer.close(index);
                                layer.msg(res.msg);
                            }
                        },
                        error: function () {
                            layer.msg("报错了");
                        }
                    });
                });
            } else if (obj.event === 'checkBuyInfo') {
                var index = layer.open({
                    title: '购买人详情',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/Member/write?code=' + data.buy_code,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'checkSellInfo') {
                var index = layer.open({
                    title: '出售人详情',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/Member/write?code=' + data.sell_code,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }
        });

    });

    /*查看大图*/
    function showImg(img) {
        if (img != '' && img != null && img != 'null') {
            var img = img.split(',');
            var imgHtml = '';
            var width = 50;
            for (i = 0; i < img.length; i++) {
                width = width + 450;
                imgHtml += "<img src='/upload/" + img[i] + "' width='400px'  style='margin-left:50px;margin-top:25px'>";
            }
            var explainopen = layer.open({
                type: 1,
                title: '图片',
                area: [width + 'px', '500px'],
                shadeClose: true,
                content: imgHtml
            });
        } else {
            layer.msg('图片为空');
        }
    }
</script>

</body>
</html>